var fasArray = new Array("208","209","210","211","212","214","215","230","231","232");
var list = new Array;

//获取当前网址，如： http://localhost:8080/Tmall/index.jsp 
var curWwwPath=window.document.location.href; 
//获取主机地址之后的目录如：/Tmall/index.jsp 
var pathName=window.document.location.pathname; 
var pos=curWwwPath.indexOf(pathName); 
//获取主机地址，如： http://localhost:8080 
var localhostPath=curWwwPath.substring(0,pos); 
var targetPath = localhostPath.replace("8080","10080");

//页面初始化后加载
$(document).ready(function() {
	$(".waikuang").mousedown(function(e)//e鼠标事件 
		{
			$(this).css("cursor", "move");//改变鼠标指针的形状 

			var offset = $(this).offset();//DIV在页面的位置 
			var x = e.pageX - offset.left;//获得鼠标指针离DIV元素左边界的距离 
			var y = e.pageY - offset.top;//获得鼠标指针离DIV元素上边界的距离 
			$(document).bind("mousemove", function(ev)//绑定鼠标的移动事件，因为光标在DIV元素外面也要有效果，所以要用doucment的事件，而不用DIV元素的事件 
			{
				$(".waikuang").stop();//加上这个之后 

				var _x = ev.pageX - x;//获得X轴方向移动的值 
				var _y = ev.pageY - y;//获得Y轴方向移动的值 

				$(".waikuang").animate({
					left : _x + "px",
					top : _y + "px"
				}, 10);
			});
		});

		$(document).mouseup(function() {
			$(".waikuang").css("cursor", "default");
			$(this).unbind("mousemove");
		});
	
	getFasStatus();
});

setInterval(function() {
	getFasStatus()
}, 1000);

//获取烟感状态数据
function getFasStatus(){
	$.ajax({
		type:'post',
		url: targetPath + '/rest/getData?start=v0&end=v29',
		dataType: 'json',//here
		success: function(result)
		{
			if(result.code=="200"){
				var data = result.data;
				if(data.length>0){
					var index = 0;
					for(var i=0;i<data.length;i++){
						if(i==0 || i%3==0){
							var object = new Object();
							object.ID = fasArray[index];
							object.B01 = data[i];
							object.D01 = data[i+1];
							object.G01 = data[i+2];
							list.push(object);
							index++;
						}
					}
				}
				if(list.length>0){
					for(var i=0;i<list.length;i++){
						var id = list[i].ID;
						var b01 = list[i].B01;
						var d01 = list[i].D01;
						var g01 = list[i].G01;
						if(b01=="0" && d01 == "0"){
							$("#"+id).attr("src","static/images/fas/GYQ_green.png");
						}
						if(b01=="0" && d01 == "1"){
							$("#"+id).attr("src","static/images/fas/GYQ_yellow.png");
						} 
						if(b01 == "1"){
							$("#"+id).attr("src","static/images/fas/GYQ_red.png");
						} 
						if(g01 == "1"){
							$("#"+id).attr("src","static/images/fas/GYQ_grey.png");
						}
//						else{
//							//蓝色
//							$("#"+id).attr("src","static/images/fas/GYQ_blue.png");
//						}
						//显示
						if($("#zhsktq").css('display')=='block'){
							if(null != devcode && '' != devcode){
								if(devcode==id){
									$("#devcode1").html(id);
									$("#devcode2").html(id);
									if(b01=="0"){
										$("#firealarm").html('无');
									}else{
										$("#firealarm").html('报警');
									}
									if(g01=='0'){
										$("#quarantine").html('无');
									}else{
										$("#quarantine").html('报警');
									}
									if(d01=="0"){
										$("#signal").html('无');
									}else{
										$("#signal").html('报警');
									}
									
								}
							}
						}
					}
				}
			}
			else{
				//code返回非200
				if(fasArray.length > 0){
					for(var i=0;i<fasArray.length;i++){
						$("#"+fasArray[i]).attr("src","static/images/fas/GYQ_blue.png");
					}
				}
			}
			
		},
		error : function(result){
			//访问出错
			//code返回非200
			if(fasArray.length > 0){
				for(var i=0;i<fasArray.length;i++){
					$("#"+fasArray[i]).attr("src","static/images/fas/GYQ_blue.png");
				}
			}
		}
	});

}

var devcode="";
function show1(obj){
//		if($("#zhsktq").css('display')=='block'){
//			
//		}
		$("#zhsktq").show();
		devcode = obj;
	
	
}

function hide1(){
	$("#zhsktq").hide();
}
